module.exports = {
    win: null,
    orders: [null, null],
    hide: function() {
        if(!this.win) return
        this.win.close()
        this.win = null
    },
    show: function() {
        this.drawWin()
    },
    drawWin: function() {
        this.win = floaty.window(
            <frame>
                <text id="infoText" gravity="left" w="*" textSize="15sp" bg="#ff0000" textColor="#ffffff">
                    贵州大学西门很好问题(23-56)[78]
                    贵州大学西门很好问题(23-12)[78]
                </text>
            </frame>
        )

        ui.run(() => {
            this.win.setPosition(0, 0)
            this.win.setSize(880, 200)
            // setTimeout(() => {    }, 100)
        })
    },
    showInfo: function(order) {
        // 如果已经在显示中，忽略
        if(this.win == null || (this.orders[1] && this.orders[1].addressEnd == order.addressEnd)) {
            return
        }
        this.orders.push(order)
        this.orders.shift()
        let info = ""
        for (let o of this.orders) {
            if(o) {
                let addressEnd = o.addressEnd.substr(0, 12)
                let tempInfo = `${addressEnd}(${o.distanceEnd}-${o.distance})[${o.time}]`
                info =  info == "" ? tempInfo : info + "\n" + tempInfo
            }
        }
        
        ui.run(() => { 
            this.win.infoText.setText(info)
        })
    }
}